//市场部周计划
Ext.namespace("MyPlan");

MyPlan.WeeklyView = function(p) {
	thiz=this;
	this.winParent = p;
	this.loadMask = null;
	
	this.planId = new Ext.form.Hidden({name:'planId'});
	this.planName = new Ext.form.TextField({
		fieldLabel: '计划名称',
		name:'planName',
		disabled:true,
		width: 340
	});
	this.createName = new Ext.form.TextField({
		fieldLabel: '制定人',
		name:'createName',
		disabled:true,
		width: 120
	});
	this.auditorName = new Ext.form.TextField({
		fieldLabel: '审核人',
		name:'auditorName',
		disabled:true,
		width: 120
	});
	this.auditNation=new Ext.form.Hidden({name:'planId'}); 
	/*this.auditNation = new Ext.form.TextArea({
		fieldLabel: '审核意见',
		name:'auditNation',
		disabled:true,
		width: 650,
		height: 45
	});*/
	this.startDate = new Ext.form.TextField({
    	fieldLabel: '计划时间',
    	name:'startDate',
    	disabled:true
	});
    this.endDate = new Ext.form.TextField({
    	fieldLabel: '～',
    	name:'endDate',
    	disabled:true,
    	labelWidth: 20,
    	labelSeparator: ''
	});
	this.files=new Ext.Container({ layout: 'column', border: false, defaults: {layout: 'form', border: false},
	        	items: []
	    });
	this.form = new Ext.FormPanel({
        region: 'north',
        bodyStyle: 'padding: 5px 5px 0',
        height: 80,
        autoScroll: true,
        labelWidth: 60,
        labelAlign: 'right',
        items: [this.planId,
        { layout: 'column', border: false, defaults: {layout: 'form', border: false},
	        	items: [ { columnWidth: .66, items: [this.planName]},
	        	            { columnWidth: .34, items: [this.createName] }]
	    },this.auditNation,
	        { layout: 'column', border: false, defaults: {layout: 'form', border: false},
	        	items: [ { columnWidth: .33, items: [this.startDate]},
	        	            { columnWidth: .33, items: [this.endDate] },
	        	            { columnWidth: .34, items: [this.auditorName] }]
	    },this.files]
    });
    
	this.renderSource = function(value){
		return OMS.TASKORIGIN[value];
	};
	this.renderCategory = function(value){
		return OMS.PLANCATEGORY[value];
	};
	this.renderStatus = function(value){
		return OMS.TASKSEXESTATUS[value];
	};
	this.renderContent=function(value){
		return Ext.util.Format.ellipsis(value,14,'...');
	}
	this.renderSend = function(value){
		return OMS.PLAN_SEND[value];
	};
	this.storeItems = new Ext.data.JsonStore({
	    url: Utils.formatURL('../myplan/listItems.form?&timesnap=' + Date.parse(new Date())),
	    root: 'result',
	    fields: ['itemId','itemCategory','itemTitle','workSource','itemContent','planWork','planFinish','itemOther','itemNation','itemRemark','taskId','taskStatus','sendFlag']
	});
	
	this.columns = [
		  {header: '明细编号',  align: 'center', width: 20,hidden:true, dataIndex: 'itemId'},
 	      {header: '任务来源',  align: 'center', width: 25, dataIndex: 'workSource',renderer:this.renderSource},   
 	      {header: '任务名称',  align: 'left',width: 40, dataIndex: 'itemTitle'},
 	      {header: '任务类别',  align: 'center', width: 25, dataIndex: 'itemCategory',renderer:this.renderCategory}, 
 	      {header: '内容描述',  align: 'left', dataIndex: 'itemContent',width:80,renderer:this.renderContent},
 	      {header: '计划实施时间',  align: 'center', hidden:true,width: 35, dataIndex: 'planWork'},
 	      {header: '完成时间',  align: 'center', width: 30, dataIndex: 'planFinish'},
 	      {header: '审核意见',  align: 'center', width: 30,dataIndex: 'itemNation',render:this.renderContent},
 	      {header: '重点、难点及需协调事宜', width: 40, hidden:true,align: 'left', dataIndex: 'itemOther'},
 	      {header: '备注',  align: 'left',width: 40, hidden:true,dataIndex: 'itemRemark'},
 	      {header: '任务编号',  align: 'center', width: 20,hidden:true, dataIndex: 'taskId'},
 	      {header: '任务性质',  align: 'center',width: 25, dataIndex: 'sendFlag',renderer:this.renderSend},
 	      {header: '任务状态',  align: 'center',width: 25,hidden:true, dataIndex: 'taskStatus',renderer:this.renderStatus}
 	];
	
	this.grid = new Ext.grid.GridPanel({
		store: this.storeItems,
        region: 'center',
        cm: new Ext.grid.ColumnModel(this.columns),
        sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
        viewConfig: { forceFit: true },
        scope:this
	});
	
	MyPlan.WeeklyView.superclass.constructor.call(this, {
		layout: 'border',
		title: '计划查看',
        width: 700,
        height: 420,
        resizable: false,
        modal: true,
        autoScroll: true,
        closeAction: 'hide',
        items: [this.form,this.grid],
		buttons:[{
            text: '关闭',
            cls: 'x-btn-text-icon btn-cancel',
            handler: this.hide.createDelegate(this, [])
        }]
    });
};
Ext.extend(MyPlan.WeeklyView, Ext.Window,{
	//取得计划信息	
	initWin:function(data){
		//this.form.getForm().reset();
		this.form.getForm().setValues(data);
		/*this.files.removeAll(true);
		var conn = new Ext.data.Connection({
			url:'../myplan/searchUpLoadFiles.form?timesnap=' + Date.parse(new Date()),
			method:'post'
		})
		Utils.request(conn,{
			params:{planId:data.planId},
			scope:this,
			success:function(data){
				var files=data.result;
				for(var i=0;i<files.length;i++){
					this.scope.addFile(files[i]);
				}
				this.scope.files.doLayout();
			}
		});	*/	
		this.grid.store.load({
			params:{planId:data.planId}
		});		
	},
	addFile:function(o){
		var href='../myplan/downloadFile.form?fileId='+o.ACCESSORY_ID+'&timesnap=' + Date.parse(new Date());
		var lbLink=new Ext.form.Label({
			html:'<a href="'+href+'">'+o.ACCESSORY_NAME+'</>',
			width:120
		});	    	
		this.files.add(lbLink);	    
	}	
});